$(function () {
    $("#jqGrid").jqGrid({
        url: '../salarywelfaremanagement/list',
        datatype: "json",
        colModel: [
            { label: 'id', name: 'id', index: 'id', width: 50, key: true ,hidden:true},
            { label: '姓名', name: 'name', index: 'name', width: 80 },
            { label: '身份证号', name: 'idno', index: 'idno', width: 80 ,hidden:true},
            // { label: '入职日期', name: 'joinDate', index: 'join_date', width: 90, formatter:"date", formatoptions: {newformat:'Y-m-d'} },
            { label: '公司', name: 'company', index: 'company', width: 80 },
            { label: '公司id', name: 'companyId', index: 'company_id', width: 80,hidden:true },
            { label: '部门', name: 'department', index: 'department', width: 80 },
            { label: '岗位名称', name: 'post', index: 'post', width: 80,formatter:getDictInfo },
            // { label: '岗位级别', name: 'postLevel', index: 'post_level', width: 80 },
            { label: '基本工资', name: 'baseSalary', index: 'base_salary', width: 80 },
            { label: '绩效工资', name: 'achievementsSalary', index: 'Achievements_salary', width: 80 },
            { label: '加班费', name: 'overtimePay', index: 'overtime_pay', width: 80 },
            { label: '工龄工资', name: 'seniorityPay', index: 'seniority_pay', width: 80 },
            { label: '其他补助', name: 'otherSubsidy', index: 'other_subsidy', width: 80 },
            { label: '交通补助', name: 'trafficSubsidy', index: 'Traffic_subsidy', width: 80 },
            { label: '通讯补助', name: 'communicationSubsidy', index: 'communication_subsidy', width: 80 },

            { label: '其他核报', name: 'otherReported', index: 'other_reported', width: 80 },
            { label: '误餐补助', name: 'wcbz', index: 'wcbz', width: 80 },
            { label: '防寒费', name: 'coldProofFee', index: 'cold_proof_fee', width: 80 },
            { label: '防署费', name: 'sunstrokeFee', index: 'sunstroke_fee', width: 80 },
            { label: '开门红', name: 'goodStartFee', index: 'good_start_fee', width: 80 },
            { label: '春节', name: 'springFestival', index: 'spring_festival', width: 80 },
            { label: '端午', name: 'dragonBoatFestival', index: 'dragon_boat_festival', width: 80 },
            { label: '中秋', name: 'midAutumnFestival', index: 'mid_autumn_festival', width: 80 },
            { label: '家属慰问', name: 'familyCondolences', index: 'family_condolences', width: 80 },
            { label: '工会春节福利', name: 'unionSpringFestivalWelfare', index: 'union_spring_festival_welfare', width: 80 },
            { label: '工会女性福利', name: 'unionWomenWelfare', index: 'union_women_welfare', width: 80 },
            { label: '儿童节', name: 'childrenDay', index: 'children_day', width: 80 },
            { label: '工会费', name: 'unionDues', index: 'union_dues', width: 80 },
            { label: '制表人', name: 'cusername', index: 'cusername', width: 80 },
            { label: '制表日期', name: 'cdate', index: 'cdate', width: 100, formatter:"date", formatoptions: {newformat:'Y-m-d'} }
        ],

		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        shrinkToFit:false,
        autoScroll: false,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	//$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
    popPage.popAllUser();
    var r = utils.getDictList("station,training");
    vm.dictList = r.station;

});

var vm = new Vue({
	el:'#rrapp',
	data:{
        q: {
            department: null,
            name: null,
            post: null,
            company: null
        },
		showList: true,
        dictList:{},
		title: null,
		salaryWelfareManagement: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.salaryWelfareManagement = {
				name:""
			};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.salaryWelfareManagement.id == null ? "../salarywelfaremanagement/save" : "../salarywelfaremanagement/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.salaryWelfareManagement),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../salarywelfaremanagement/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../salarywelfaremanagement/info/"+id, function(r){
                vm.salaryWelfareManagement = r.salaryWelfareManagement;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{
                    'name': vm.q.name,
                    'post': vm.q.post,
                    'company': vm.q.company,
                    'department': vm.q.department},
                page:page
            }).trigger("reloadGrid");
		},


        popUser: function(){
            // popPage.popUserGrid();
            var page = $("#popGrid").jqGrid('getGridParam','page');
            $("#popGrid").jqGrid('setGridParam',{
                postData:{
                    'iswork': '1',
                    'isHuashun': 'Y',
                   },
                page:page
            }).trigger("reloadGrid");
            layer.open({
                type: 1,
                offset: '50px',
                skin: 'layui-layer-molv',
                title: "选择员工",
                area: ['750px', '400px'],
                shade: 0,
                shadeClose: false,
                content: jQuery("#popLayer"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    var grid = $("#popGrid");
                    var rowKey = grid.getGridParam("selrow");
                    if(!rowKey){
                        alert("请选择一条记录");
                        return ;
                    }
                    var rowData=grid.jqGrid("getRowData",rowKey);
                    vm.salaryWelfareManagement.name=rowData.name;
                    vm.salaryWelfareManagement.idno=rowData.idno;
                    vm.salaryWelfareManagement.company=rowData.company;
                    vm.salaryWelfareManagement.companyid=rowData.companyId;
                    vm.salaryWelfareManagement.department=rowData.department;
                    vm.salaryWelfareManagement.departmentId=rowData.deptNo;

                    vm.salaryWelfareManagement.post=rowData.post;
                    layer.close(index);
                }
            });
        },
     /*   popPage: function(){
            utils.popGrid();
            layer.open({
                type: 1,
                offset: '50px',
                skin: 'layui-layer-molv',
                title: "选择员工",
                area: ['800px', '450px'],
                shade: 0,
                shadeClose: false,
                content: jQuery("#popLayer"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    var grid = $("#popGrid");
                    var rowKey = grid.getGridParam("selrow");
                    if(!rowKey){
                        alert("请选择一条记录");
                        return ;
                    }
                    var rowData=grid.jqGrid("getRowData",rowKey);
                    vm.salaryWelfareManagement.name=rowData.name;
                    vm.salaryWelfareManagement.idno=rowData.idno;
                    vm.salaryWelfareManagement.company=rowData.company;
                    vm.salaryWelfareManagement.companyId=rowData.companyId;
                    vm.salaryWelfareManagement.department=rowData.department;
                    vm.salaryWelfareManagement.joinDate=rowData.joinDate;
                    vm.salaryWelfareManagement.postLevel=rowData.postLevel;

                    vm.salaryWelfareManagement.post=rowData.post;

                    //alert(JSON.stringify( vm.safetyEducationManagement));


                    layer.close(index);
                }
            });
        },*/
	}
});